package net.lym.es.index;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

/**
 * ES 测试 ：索引-查询
 */
public class ESTest_Index_Search {
    public static void main(String[] args) throws Exception {

        // 创建 ES 客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
        );

        // 查询索引 - 请求对象
        GetIndexRequest request = new GetIndexRequest("user");

        // 发送请求，获取响应
        GetIndexResponse getIndexResponse = esClient.indices().get(request, RequestOptions.DEFAULT);

        // 响应状态
        System.out.println("aliases:" + getIndexResponse.getAliases());//别名
        System.out.println("mappings:" + getIndexResponse.getMappings());//映射
        System.out.println("settings:" + getIndexResponse.getSettings());//设置

        // 关闭 ES 客户端
        esClient.close();
    }
}
